package com.qf.work;

import com.qf.util.RabbitMQUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;

/**
 * @author zjw
 * @description  workQueue模式生产者
 * @date 2021/11/8 16:27
 */
public class Publisher {

    @Test
    public void test() throws Exception {
        //1. 获取连接对象
        Connection connection = RabbitMQUtil.getConnection();

        //2. 构建Channel
        Channel channel = connection.openChannel().get();

        //3. 发送消息到默认交换机，指定路由规则
        for (int i = 0; i < 10; i++) {
            channel.basicPublish("","work_queue",null,("Work" + i).getBytes());
        }

        //4. 释放资源
        channel.close();
        connection.close();
    }

}
